package edu.gyc.mysystem.controller;

import com.github.pagehelper.PageInfo;
import edu.gyc.mysystem.dao.StudentMapper;
import edu.gyc.mysystem.model.Student;
import edu.gyc.mysystem.service.StuService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.List;

@Slf4j
@Controller
@RequestMapping("/stu")
public class StuController {
    @Autowired
    StuService stuService;

//    @RequiresPermissions("stu:list")
    @RequestMapping("/list")
    public String list(@RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum,
                       @RequestParam(defaultValue = "2", value = "pageSize") Integer pageSize,
                       HttpSession session) {
        PageInfo<Student> pageData = stuService.getStusByPageNo(pageNum, pageSize);
        session.setAttribute("stus", pageData.getList());
        session.setAttribute("currentPage", pageData.getPageNum());
        session.setAttribute("totalPage", pageData.getPages());
        return "admin/student";
    }
//    @RequiresPermissions("stu:add")
    @RequestMapping("/add")
    public String add(Student student, Model model) {
        log.info("调用学生控制器的添加方法");
        return "admin/student";
    }
//    @RequiresPermissions("stu:del")
    @RequestMapping("/del")
    public String del(Integer id, Model model) {
        log.info("调用学生控制器的删除方法");
        return "admin/student";
    }
//    @RequiresPermissions("stu:update")
    @RequestMapping("/update")
    public String update(Student student, Model model) {
        log.info("调用学生控制器的更新方法");
        return "admin/student";
    }
}
